package com.ymatou.iapi.userservice.testcase;

import java.util.Random;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.userservice.parameter.req.CreateUserReq;
import com.ymatou.iapi.userservice.parameter.req.SetUserLevelReq;
import com.ymatou.iapi.userservice.service.SetUserLevelCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.database.model.Userinfo;
import com.ymttest.database.model.Userinfoex;
import com.ymttest.database.sqlwapper.JUserWapper;
import com.ymttest.utils.TestDataManager;

/**
 * 绑定邮箱Test FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_SetUserLevel {
	private static SetUserLevelReq SetUserLevelBean;
	private static SetUserLevelCall SetUserLevelCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("设置用户等级");
	}

	@Before
	public void caseUp() {
		SetUserLevelBean = new SetUserLevelReq();
		SetUserLevelCall = new SetUserLevelCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(SetUserLevelCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_SetUserLevel_001() {
		Logger.start(true, "设置用户等级,成功");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
			Integer level = new Random().nextInt(6) + 1;
			SetUserLevelBean.setLevel(level);
			SetUserLevelBean.setUserId(uid);
			SetUserLevelCall.setData(SetUserLevelBean);
			SetUserLevelCall.callService();
			Logger.verifyEquals("true", SetUserLevelCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", SetUserLevelCall.getString("ResponseCode"), "验证ResponseCode");
			Userinfo info = new JUserWapper().selectUserinfoByUid(uid).get(0);
			Logger.verifyEquals(info.getUserLevel(), level, "验证level");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_SetUserLevel_002() {
		Logger.start(false, "不存在用户设置用户等级,成功");
		try {
			Integer level = new Random().nextInt(6) + 1;
			SetUserLevelBean.setLevel(level);
			SetUserLevelBean.setUserId(-1);
			SetUserLevelCall.setData(SetUserLevelBean);
			SetUserLevelCall.callService();
			Logger.verifyEquals("false", SetUserLevelCall.getString("Success"), "验证Success");
			Logger.verifyEquals("100", SetUserLevelCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyIsContains("用户ID未提供", SetUserLevelCall.getString("LastErrorMessage"), "验证LastErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_SetUserLevel_003() {
		Logger.start(false, "错误用户等级,失败");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
			Integer level = 8;
			SetUserLevelBean.setLevel(level);
			SetUserLevelBean.setUserId(uid);
			SetUserLevelCall.setData(SetUserLevelBean);
			SetUserLevelCall.callService();
			Logger.verifyEquals("false", SetUserLevelCall.getString("Success"), "验证Success");
			Logger.verifyEquals("100", SetUserLevelCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyIsContains("Level must be between 1 and 7", SetUserLevelCall.getString("LastErrorMessage"), "验证LastErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_SetUserLevel_004() {
		Logger.start(false, "不输入uid,失败");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
			Integer level = 1;
			SetUserLevelBean.setLevel(level);
//			SetUserLevelBean.setUserId(uid);
			SetUserLevelCall.setData(SetUserLevelBean);
			SetUserLevelCall.callService();
			Logger.verifyEquals("false", SetUserLevelCall.getString("Success"), "验证Success");
			Logger.verifyEquals("100", SetUserLevelCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyIsContains("用户ID未提供", SetUserLevelCall.getString("LastErrorMessage"), "验证LastErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_SetUserLevel_005() {
		Logger.start(false, "不输入level,失败");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
			Integer level = 1;
//			SetUserLevelBean.setLevel(level);
			SetUserLevelBean.setUserId(uid);
			SetUserLevelCall.setData(SetUserLevelBean);
			SetUserLevelCall.callService();
			Logger.verifyEquals("false", SetUserLevelCall.getString("Success"), "验证Success");
			Logger.verifyEquals("100", SetUserLevelCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyIsContains("Level must be between 1 and 7", SetUserLevelCall.getString("LastErrorMessage"), "验证LastErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}